﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;

namespace Financial
{
    class QuoteTable
    {
        public QuoteTable() { }

        public DataTable CreateDataTable(string tableName, string[] columnNames, ArrayList quotes)
        {
            DataTable table = new DataTable(tableName);
            for (int i = 0; i < columnNames.Length; i++)
            {
                table.Columns.Add(new DataColumn(columnNames[i], typeof(string)));
            }
            for (int i = 0; i < quotes.Count; i++)
            {
                table.Rows.Add(CreateRowFromQuote(table.NewRow(), (Quote)quotes[i]));
            }
            return table;
        }

        private DataRow CreateRowFromQuote(DataRow row, Quote quote)
        {
            row[0] = quote.Name;
            row[1] = quote.Ask;
            row[2] = quote.Change_And_Percent_Change;
            row[3] = quote.Days_Low;
            row[4] = quote.Days_High;
            row[5] = quote.Fifty_Two_Week_Low;
            row[6] = quote.Fifty_Two_Week_High;
            row[7] = quote.Symbol;
            return row;
        }
    }
}
